package com.sunrise.visual.frame.common
{
	import mx.controls.Alert;
	
	public class GaugeUtil
	{
		private var config:Object;
		private var config2:Object;
		private var data:String;
		
		private var titleEnabled:String;
		private var title:String;
		private var minValue:String;
		private var maxValue:String;
		private var major_interval:String;
		private var color1_minValue:String;
		private var color1_maxValue:String;
		private var color1:String;
		private var color2_minValue:String;
		private var color2_maxValue:String;
		private var color2:String;
		private var color3_minValue:String;
		private var color3_maxValue:String;
		private var color3:String;
		public function GaugeUtil(data:String,config:Object,config2:Object)
		{
			this.data = data;
			this.config = config;
			this.config2 = config2;
		}
		
		public function getXML():XML {
			var xml:XML = <anychart>
							<margin all="-20"/>
							<settings>
								<animation enabled="true"/>
							</settings>
							<gauges>
								<gauge>
									<chart_settings>
										<title enabled={this.titleEnabled}>
											<text>{this.title}</text>
										</title>
										<chart_background enabled="false"/>
									</chart_settings>
									<circular>
										<margin all="0"/>
										<axis start_angle="30" sweep_angle="300"  >
											<scale minimum={this.minValue} maximum={this.maxValue} major_interval={this.major_interval} />
											<color_ranges>
												<color_range start={this.color1_minValue} end={this.color1_maxValue} color={this.color1} align="Inside" padding="40">
													<border enabled="true" color="Black" opacity="0.2"/>
													<fill opacity="0.7"/>
												</color_range>
												<color_range start={this.color2_minValue} end={this.color2_maxValue} color={this.color2} align="Inside" padding="40">
													<border enabled="true" color="Black" opacity="0.2"/>
													<fill opacity="0.7"/>
												</color_range>
													<color_range start={this.color3_minValue} end={this.color3_maxValue} color={this.color3} align="Inside" padding="40">
													<border enabled="true" color="Black" opacity="0.2"/>
													<fill opacity="0.7"/>
												</color_range>
											</color_ranges>
									<scale_bar>
									<fill color="White"/>
									<effects enabled="true">
									<drop_shadow enabled="true" distance="2" blur_x="2" blur_y="2" opacity="0.7"/>
									</effects>
									</scale_bar>
			
							   <labels enabled="true" align="Inside" padding="6" rotate_circular="true" auto_orientation="false" >
							            <format><![CDATA[{%Value}{numDecimals:0}]]></format>
<font family="Microsoft Yahei"  color="White"  bold="false">
							              <effects enabled="true">
							                <drop_shadow enabled="true"/>
							              </effects>
							            </font>
							          </labels>
										</axis>
										<frame type="Rectangular">
											<inner_stroke enabled="false"/>
											<outer_stroke enabled="false"/>
											<corners type="Rounded" all="15"/>
											<background enabled="false">
												<border  color="Gray" opacity="0.5"/>
											</background>
										</frame>
										<pointers>
											<pointer type="Needle" value={this.data||"0"} color="#00699C">
												<label enabled="true">
<font family="Microsoft Yahei" size="14" bold="true" color={this.config.formatColor} />
													<format>{"{%Value}{numDecimals:"}{this.config.format_value || "0"}{"}"}{this.config.formatUtil||""}</format>
													<position placement_mode="ByPoint" x="50" y="90" valign="Center" halign="Center"/>
													<background enabled="false"/>
												</label>
												<needle_pointer_style base_radius="-50">
													<cap>
														<background>
															<fill type="Gradient">
																<gradient type="Linear" angle="45">
																	<key color="#D3D3D3"/>
																	<key color="#6F6F6F"/>
																</gradient>
															</fill>
															<border color="Black" opacity="0.9"/>
														</background>
														<effects enabled="true">
															<bevel enabled="true" distance="2" shadow_opacity="0.6" highlight_opacity="0.6"/>
															<drop_shadow enabled="true" distance="1.5" blur_x="2" blur_y="2" opacity="0.4"/>
														</effects>
													</cap>
													<effects enabled="true">
														<drop_shadow enabled="true" distance="2" opacity="0.5" blur_x="2" blur_y="2" color="Black"/>
														<bevel enabled="true" distance="2" shadow_opacity="0.5" highlight_opacity="0.5"/>
													</effects>
												</needle_pointer_style>
												<animation enabled="true" start_time="0" duration="1" interpolation_type="Elastic"/>
											</pointer>
										</pointers>
									</circular>
								</gauge>
							</gauges>
						</anychart>;
			return xml;
		}
		public function parseXML():XML {
			this.titleEnabled = this.config.titleEnabled || "false";
			this.title = this.config.title || "";
			this.minValue = this.config.minValue || "0";
			this.maxValue = this.config.maxValue || "100";
			this.major_interval = this.config.major_interval || "10";
			this.color1_minValue = this.config2.color1_minValue || "0";
			this.color1_maxValue = this.config2.color1_maxValue || "60";
			this.color1 = this.config.color1 || "#FAFA02";
			this.color2_minValue = this.config2.color2_minValue || "60";
			this.color2_maxValue = this.config2.color2_maxValue || "100";
			this.color2 = this.config.color2 || "#66FE66";
			this.color3_minValue = this.config2.color3_minValue || "60";
			this.color3_maxValue = this.config2.color3_maxValue || "100";
			this.color3 = this.config.color3 || "#66FE66";
			if(this.config.formatColor){
			    if(this.data>=this.minValue&&this.data<this.color1_maxValue){
					this.config.formatColor=this.color1;
				}else if(this.data>=this.color1_maxValue&&this.data<=this.color2_maxValue){
					this.config.formatColor=this.color2;
				}else{
					this.config.formatColor=this.color3;
				}
				
			}else{
				this.config.formatColor="white";
			}
			
			var xml:XML = this.getXML();
			return xml;
		}
	}
}